/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package treenode;

/**
 *
 * @author k00104663
 */
public class TreeNode {

    
   // package access members
      TreeNode left;   // left node
      int data;        // data item	          - data will differ depending on the application.
      TreeNode right;  // right node
   
   // Constructor: initialize data to d and make this a leaf node
      public TreeNode( int d )
      { 
         data = d;              
         left = right = null;  // this node has no children
      } 
      
   // Insert a TreeNode into a Tree that contains nodes.( Ignore duplicate values).
      public synchronized void insert( int d )
      {    if ( d < data ) {
            	if ( left == null )
               		left = new TreeNode( d );
            	else
               		left.insert( d );       	}
         else if ( d > data ) {
            	if ( right == null )
               		right = new TreeNode( d );
            	else
               		right.insert( d );         }
      }
   
    public static void main(String[] args) {
                Tree tree = new Tree( );
         int intVal;
      
         System.out.println( "Inserting the following values: " );
      
         for ( int i = 1; i <= 10; i++ ) {
            intVal = ( int ) ( Math.random() * 100 );
            System.out.print( intVal + " " );
            tree.insertNode( intVal );
    }
}
}